package com.roger.tool.utils;

import android.content.Context;
import android.os.Handler;

public class HandlerUtils {

	private static Handler mHandler;

	public static void init(Context pContext) {
		try {
			mHandler = new Handler(pContext.getMainLooper());
		} catch (Exception e) {
		}
	}

	public static void post(Runnable pRunnable) {
		if (pRunnable != null) {
			if (mHandler != null) {
				mHandler.post(pRunnable);
			} else {
				pRunnable.run();
			}
		}
	}

	public static void postDelayed(Runnable pRunnable, long delayMillis) {
		if (pRunnable != null) {
			if (mHandler != null) {
				mHandler.postDelayed(pRunnable, delayMillis);
			} else {
				pRunnable.run();
			}
		}
	}

	/**
	 * 删除指定的Runnable对象，使线程对象停止运行
	 * 
	 * @param pRunnable
	 */
	public static void removeCallbacks(Runnable pRunnable) {

		if (pRunnable != null) {
			if (mHandler != null) {
				mHandler.removeCallbacks(pRunnable);
			}
		}

	}

}
